﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UofCASE.AgileProductLinerDSL.Nant.Tasks.Models;
using System.IO;
using APLDTests.NantTests.Mocks;

namespace APLDTests.NantTests
{

    [TestClass]
    public class TestBeforeRun
    {
        ITest test;

        [TestInitialize]
        public void setup()
        {
            test = new Test(new FileInfo("../../../APLDTests/AcceptanceTests/Feature1Test.html"));
            AspenFSProxy proxy = new DummyProxy("../../../APLDTests/SampleProductLinerDir/Platforms/Windows", new FileInfo("../../../APLDTests/AspenCollectionPlan.xml"), "APLDTests.dll");
            test.Owner = proxy;
        }

        [TestMethod]
        [ExpectedException(typeof(NoResultException))]
        public void PassesThrowsNoResultException()
        {
            bool b = test.Passed;
        }

        [TestMethod]
        [ExpectedException(typeof(NoResultException))]
        public void FailuresThrowsNoResultException()
        {
            bool b = test.Failed;
        }

        [TestMethod]
        public void HasMatchingKey()
        {
            ITest other = new Test(new FileInfo("../../../APLDTests/AcceptanceTests/Feature2Test.html"));
            ITestKey key = test.Key;

            Assert.IsTrue(key.Matches(test));
            Assert.IsFalse(key.Matches(other));
        }

    }

    [TestClass]
    public class TestAfterPassingRun
    {
        ITest test;

        [TestInitialize]
        public void setup()
        {
            test = new Test(new FileInfo("../../../APLDTests/AcceptanceTests/Feature1Test.html"));
            AspenFSProxy proxy = new DummyProxy("../../../APLDTests/SampleProductLinerDir/Platforms/Windows", new FileInfo("../../../APLDTests/AspenCollectionPlan.xml"), "APLDTests.dll");
            test.Owner = proxy;
            test.Run();
        }

        [TestCleanup]
        public void teardown()
        {
            Directory.Delete("../../../APLDTests/SampleProductLinerDir/Platforms/Windows/Results", true);
        }

        [TestMethod]
        public void DidPass()
        {
            Assert.IsTrue(test.Passed);
        }

        [TestMethod]
        public void DidNotFail()
        {
            Assert.IsFalse(test.Failed);
        }

    }

    [TestClass]
    public class TestAfterFailingRun
    {
        ITest test;

        [TestInitialize]
        public void setup()
        {
            test = new Test(new FileInfo("../../../APLDTests/AcceptanceTests/Feature2Test.html"));
            AspenFSProxy proxy = new DummyProxy("../../../APLDTests/SampleProductLinerDir/Platforms/Windows", new FileInfo("../../../APLDTests/AspenCollectionPlan.xml"), "APLDTests.dll");
            test.Owner = proxy;
            test.Run();
        }

        [TestCleanup]
        public void teardown()
        {
            Directory.Delete("../../../APLDTests/SampleProductLinerDir/Platforms/Windows/Results", true);
        }

        [TestMethod]
        public void DidNotPass()
        {
            Assert.IsFalse(test.Passed);
        }

        [TestMethod]
        public void DidFail()
        {
            Assert.IsTrue(test.Failed);
        }
    }

}
